package com.ssy.lingxi.marketing.controller.web;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.marketing.model.vo.coupon.request.*;
import com.ssy.lingxi.marketing.model.vo.coupon.response.*;
import com.ssy.lingxi.marketing.service.IMobileCouponService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu Web - 优惠券
 * @author yzc
 * @version 2.0.0
 * @date 2021/9/6
 */
@RestController
@RequestMapping("/marketing/web/coupon")
public class WebCouponController extends BaseController {

    @Resource
    private IMobileCouponService mobileCouponService;

    /**
     * 我的优惠券 - 分页列表
     **/
    @RequestMapping(value = "/detail/page", method = RequestMethod.GET)
    public Wrapper<PageData<WebCouponDetailResponse>> pageCouponDetail(@Valid WebCouponPageRequest request) {
        UserLoginCacheDTO loginUser = isLogin() ? getSysUser() : null;
        return mobileCouponService.pageCouponDetailByWeb(loginUser, request);
    }

    /**
     * 我的优惠券 - 数量统计
     **/
    @RequestMapping(value = "/detail/count", method = RequestMethod.GET)
    public Wrapper<MobileCouponDetailCountResponse> getCouponCount(@Valid MobileCouponDetailCountRequest request) {
        UserLoginCacheDTO loginUser = isLogin() ? getSysUser() : null;
        return mobileCouponService.getCouponCount(loginUser, request);
    }

    /**
     * 进货单领券 - 店铺优惠券列表
     */
    @RequestMapping(value = "/list/by/shop", method = RequestMethod.GET)
    public Wrapper<List<MobileCouponResponse>> listShopCoupon(@Valid MobileShopCouponListRequest request) {
        UserLoginCacheDTO loginUser = isLogin() ? getSysUser() : null;
        return mobileCouponService.listShopCoupon(loginUser, request);
    }

    /**
     * 活动页 - 自动领取优惠券
     **/
    @RequestMapping(value = "/auto/receive", method = RequestMethod.POST)
    public Wrapper<List<MobileCouponDetailResponse>> autoReceiveCoupon(@Valid @RequestBody AutoReceiveCouponRequest request) {
        UserLoginCacheDTO loginUser = isLogin() ? getSysUser() : null;
        return mobileCouponService.autoReceiveCoupon(loginUser, request);
    }

    /**
     * 用户领取优惠券
     **/
    @RequestMapping(value = "/receive", method = RequestMethod.POST)
    public Wrapper<ReceiveCouponResponse> receiveCoupon(@Valid @RequestBody ReceiveCouponRequest request) {
        UserLoginCacheDTO loginUser = getSysUser();
        return mobileCouponService.receiveCoupon(loginUser, request);
    }

    /**
     * 提交订单 - 选择的优惠券列表
     **/
    @RequestMapping(value = "/list/by/order", method = RequestMethod.POST)
    public Wrapper<List<MobileCouponDetailCanUseResponse>> listOrderCouponDetail(@Valid @RequestBody MobileGoodsCartRequest request) {
        UserLoginCacheDTO loginUser = getSysUser();
        return mobileCouponService.listOrderCouponDetail(loginUser, request);
    }

    /**
     * 查询优惠券所关联的商品信息
     **/
    @RequestMapping(value = "/goods/list", method = RequestMethod.POST)
    public Wrapper<List<MobileActivityRelationGoodsResp>> listMerchantCouponRelationGoods(@Valid @RequestBody MobileCouponGoodsRelationReq request) {
        UserLoginCacheDTO loginUser = isLogin() ? getSysUser() : null;
        return mobileCouponService.listMerchantCouponRelationGoodsSku(loginUser, request);
    }

}
